-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed dispatching to correct method and removed StackOverflowError #1
base: main
Are you sure you want to change the base?
Conversation
Hi, |
if (kunde instanceof Privatkunde p) return calculateMwSt(p, wert); | ||
else if (kunde instanceof Businesskunde b) return calculateMwSt(b, wert); | ||
else throw new IllegalArgumentException("Unsupported type: " + kunde.getClass()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of MwStRechner.PlainOOP
was to demonstrate a base implementation which is free of everything modern, like the Type Pattern.
To have a simple single step experience, I favor the pure instanceof Operator in this place. This way a Type Cast is required, but the demo of the Type Pattern may benefit also. The usage of the Type Pattern is demonstrated in the next step MwStRechner.InstanceOfPattern#calculateMwSt
.
Suggestion for line 21-23:
if (kunde instanceof Privatkunde) return calculateMwSt((Privatkunde) p, wert);
else if (kunde instanceof Businesskunde) return calculateMwSt((Businesskunde)b, wert);
else throw new IllegalArgumentException("Unsupported type: " + kunde.getClass());
And of course, this all happened because I omitted tests because "it just a demo".. I'll add some soon. |
Of course, we all do that :-) |
@kabutz I implemented tests and fixed the problem as suggested, see main. I'll close this PR okay? |
8b440b7
to
713174e
Compare
Mistake in article causes a StackOverflowError